package com.woniuxy.handler;

import com.alibaba.fastjson2.JSON;
import com.woniuxy.util.ResponseData;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @author：xurice
 * @date：Created in 2024/4/22 20:16
 * @description：
 * @modified By：
 * @version: $
 */
@Component
public class ChangeDbHandler extends OncePerRequestFilter {
    @Override
    protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException {
        HttpSession session = httpServletRequest.getSession();
        String db = (String) session.getAttribute("db");
        if (db==null){
            session.setAttribute("db","master");
            filterChain.doFilter(httpServletRequest,httpServletResponse);
            return;
        }
        session.setAttribute("db",db);
        filterChain.doFilter(httpServletRequest,httpServletResponse);
    }
}
